package com.kokomi.confirm_model;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;


@SpringBootTest
public class MessageConfirmTest {
    @Autowired
    private RabbitTemplate rabbitTemplate;


    //消息到达
    @Test
    public void testArrived() {
        // 正常测试：为消息指定一个唯一的CorrelationData对象，以便在确认回调时可以关联到具体的消息
        rabbitTemplate.convertAndSend("confirm.direct.exchange", "msg.confirm",
                "我是男生", new CorrelationData("i-am-boy"));
    }


    //消息未到达
    @Test
    public void testNotArrived() {
        // 测试消息：未送达交换机，触发消息确认回调 (交换机不存在)
        rabbitTemplate.convertAndSend("confirm.direct.exchange.not.exists", "msg.confirm",
                "她是女生", new CorrelationData("i-am-girl"));
    }

}
